<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="util.DBUtil" %>
<%@ page import="dao.MaterialDao" %>
<%@ page import="entity.MaterialBean" %>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>产品信息列表</title>
    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="css/user.css">
    <script src="js/user.js"></script>
</head>

<body>

<div class="container-fluid">
    <div class="row">

        <div class="col-sm-12" id="right">
            <ol class="breadcrumb">
                <li class="active">菜单
                </li>
                <li class="active">编辑物料信息
                </li>
            </ol>

            <div class="panel panel-default">
                <div class="panel-heading">
                    填写物料信息
                </div>
                <div class="panel-body">
                    <%
                        request.setCharacterEncoding("UTF-8");

                        /*分两种情况
                         * 1.刚点击修改跳转至edit页面————根据id获取原始信息
                         * 2.用户已经修改了数据，但输入违法，需要保存上一次输入，再次刷新显示
                         */
                        int editBackFlag=0;
                        if(request.getAttribute("editBackFlag")!=null)
                            editBackFlag = (int)request.getAttribute("editBackFlag");
                        MaterialBean obj = (MaterialBean) request.getAttribute("obj");
                        int curpage = (int)request.getAttribute("curpage");
                        int pageCount = (int)request.getAttribute("pageCount");
                        System.out.println("material_edit pageCount="+pageCount);
                        System.out.println("material_edit curpage="+curpage);
                        System.out.println("material_edit obj.getId():"+obj.getId());
                        System.out.println("material_edit obj.getitemId():"+obj.getId());
                        System.out.println("material_edit obj.getitemName():"+obj.getItemId());
                        System.out.println("material_edit obj.getitemClasses():"+obj.getItemName());
                        System.out.println("material_edit obj.getitemClasses():"+obj.getItemClasses());

                    %>
                    <form role="form" class="form-horizontal"
<%--                          action="<%if(i==0)out.print("MaterialAddServlet");else out.print("MaterialEditServlet?id="+i);%>"--%>
                          action="<%="MaterialSaveServlet"%>?curpage=<%=curpage%>&pageCount=<%=pageCount%>&id=<%=obj.getId()%>"
                          method="post">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">物料编号<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="itemId" name="itemId"
                                       value="<%=obj.getItemId()%>"
                                       placeholder="请输入物料编号">
                                <span id="itemIdError" class="errortext">
                                   <%
                                       if (obj.getItemId() != null&&editBackFlag==1) {
                                           if (obj.getItemId() == "") {
                                               out.println("物料编号不能为空");
                                           } else if (obj.getItemId().length() != 9&&editBackFlag==1) {
                                               out.println("格式错误,长度应为9个数字");
                                           }
                                       }
                                   %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">物料名称<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="itemName" name="itemName"
                                       value="<%=obj.getItemName()%>"
                                       placeholder="请输入物料名称">
                                <span id="itemNameError" class="errortext">
                                  <%
                                      if (obj.getItemName() != null&&editBackFlag==1) {
                                          if (obj.getItemName() == "") {
                                              out.println("姓名不能为空");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">材料类型<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <select class="form-control" id="itemClasses" name="itemClasses">
                                    <option value="">请选择</option>
                                    <option value="金属" <% if (obj.getItemClasses().equals("金属"))
                                        out.print("selected"); %> >金属
                                    </option>
                                    <option value="合金" <% if (obj.getItemClasses().equals("合金")) out.print("selected"); %> >
                                        合金
                                    </option>
                                    <option value="复合材料" <% if (obj.getItemClasses().equals("复合材料"))
                                        out.print("selected"); %> >
                                        复合材料
                                    </option>
                                    <option value="其它" <% if (obj.getItemClasses().equals("其它")) out.print("selected"); %> >
                                        其它
                                    </option>
                                </select>
                                <span id="itemClassesError" class="errortext">
                                  <%
                                      if (obj.getItemClasses() != null&&editBackFlag==1) {
                                          if (obj.getItemClasses() == "") {
                                              out.println("请选择材料类型");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">供应商名称<sup
                                    class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="vendorName" name="vendorName"
                                       value="<%=obj.getVendorName()%>"
                                       placeholder="请输入供应商名称">
                                <span id="vendorNameError" class="vendorNametext"style="color: red">
                                  <%
                                      if (obj.getVendorName() != null&&editBackFlag==1) {
                                          if (obj.getVendorName() == "") {
                                              out.println("供应商名称不能为空");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">厂址<sup
                                    class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="site" name="site"
                                       value="<%=obj.getSite()%>"
                                       placeholder="请输入厂址">
                                <span id="siteError" class="errortext">
                                  <%
                                      if (obj.getSite() != null&&editBackFlag==1) {
                                          if (obj.getSite() == "") {
                                              out.println("厂址不能为空");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">入库时间<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="date" class="form-control" id="inboundTime" name="inboundTime"
                                       value="<%=obj.getInboundTime()%>"
                                       placeholder="请输入入库时间">
                                <span id="inboundTimeError" class="errortext">
                                  <%
                                      if (obj.getInboundTime() != null&&editBackFlag==1) {
                                          if (obj.getInboundTime() == "") {
                                              out.println("入库时间不能为空");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">物料说明</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="itemDescription" name="itemDescription"
                                       value="<%=obj.getItemDescription()%>"
                                       placeholder="请输入物料说明">

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">联系人<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="contact" name="contact"
                                       value="<%=obj.getContact()%>"
                                       placeholder="请输入联系人姓名">
                                <span id="contactError" class="errortext">
                                  <%
                                      if (obj.getContact() != null&&editBackFlag==1) {
                                          if (obj.getContact() == "") {
                                              out.println("联系人不能为空");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">手机号<sup
                                    class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="phoneNumber" name="phoneNumber"
                                       value="<%=obj.getPhoneNumber()%>"
                                       placeholder="请输入手机号">
                                <span id="phonenumberError" class="errortext">
                                  <%
                                      String re = "1\\d{10}";
                                      if (obj.getPhoneNumber() != null&&editBackFlag==1) {
                                          if (obj.getPhoneNumber() == "") {
                                              out.println("手机号不能为空");
                                          } else if (!obj.getPhoneNumber().matches(re)) {
                                              out.println("手机号格式输入错误");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-primary">保存</button>
                                <button type="reset" class="btn btn-default">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

</body>

</html>
